﻿using System;
using ETModel;
using UnityEngine;

namespace ETHotfix {
    [ObjectSystem]
    public class OperaComponentAwakeSystem : AwakeSystem<OperaComponent> {
        public override void Awake(OperaComponent self) {
            self.Awake();
        }
    }

    [ObjectSystem]
    public class OperaComponentUpdateSystem : UpdateSystem<OperaComponent> {
        public override void Update(OperaComponent self) {
            self.Update();
        }
    }

    public class OperaComponent : Component {

        private Unit _operaUnit;

        private Component _uiComp;

        public Vector3 ClickPoint;
        public Unit OperaUnit {
            get {
                return _operaUnit;
            }
            set {
                _operaUnit = value;
            }
        }

        public int mapMask;

        public void Awake() {
            this.mapMask = LayerMask.GetMask("Map");
            _uiComp = Game.Scene.GetComponent<UIComponent>();
        }

        private readonly Frame_ShootBox frameShootBox = new Frame_ShootBox();

        public void Update() {
            if (OperaUnit == null || OperaUnit.IsDisposed) return;


            if (Input.GetKeyDown(KeyCode.Space)) {
                //按下空格,往摄像头方向发一个方块

            }
            if (Input.GetMouseButtonDown(1)) {
                //左键往指针头方向发一个方块
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                frameShootBox.X = ray.direction.x;
                frameShootBox.Y = ray.direction.y;
                frameShootBox.Z = ray.direction.z;
                SessionComponent.Instance.Session.Send(frameShootBox);
            }

        }
    }
}
